package cn.cloud9.designpattern.dp02factory.simplefactory;

import cn.cloud9.designpattern.dp02factory.simplefactory.product.Course;
import cn.cloud9.designpattern.dp02factory.simplefactory.product.JavaCourse;
import cn.cloud9.designpattern.dp02factory.simplefactory.product.PythonCourse;

/**
 * @author OnCloud9
 * @description https://www.bilibili.com/video/BV1L5411R7BP?p=2
 * @project Java
 * @date 2022年05月22日 10:14
 */
public class SimpleFactory {

    public static Course build(Class<?> clazz) {
        try {
            return (Course) clazz.newInstance();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return null;
    }

    /**
     * 使用工厂类来分配对象
     * @param args
     */
    public static void main(String[] args) {
        Course course = SimpleFactory.build(JavaCourse.class);
        course.record();
        course = SimpleFactory.build(PythonCourse.class);
        course.record();
    }
}
